package Sort;

public class MyQuick {

    public static void quickSort(int[] arr){
        recursion(arr,0,arr.length - 1);
    }

    private static void recursion(int[] arr,int left,int right){
        if (left >= right){
            return;
        }

        int mid = benchmark(arr,left,right);
        recursion(arr,left,mid - 1);
        recursion(arr,mid + 1,right);

    }

    private static int benchmark(int[] arr,int left,int right){
        int temp = arr[right];
        int j = left;
        int i = left;
        while (j < right){
            if (arr[j] < temp){
                if (j != i){
                  swap(arr,i,j);
                }
                i++;
            }
            j++;
        }
        swap(arr,right,i);
        return i;
    }

    private static void swap(int[] arr,int i,int j){
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}
